package com.smallframework.webserver;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * Description:
 * User: Administrator
 * DateTime: 2017/6/10 0010 11:39
 */
public class HttpServer {

    public static final String WEB_ROOT = System.getProperty("user.dir") + File.separator + "webapp";
    private volatile boolean running = false;

    public void await() {
        ServerSocket server = null;
        try {
            server = new ServerSocket(8080);
            running = true;
        } catch (IOException e) {
            e.printStackTrace();
        }

        while (running) {
            Socket socket = null;
            InputStream input = null;
            OutputStream output = null;
            try {
                socket = server.accept();
                new Thread(new Handler(socket)).start();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

    public static void main(String[] args) {
        HttpServer server = new HttpServer();
        server.await();
    }
}
